package points 
{
	import constants.Colors;
	import constants.utils;
	/**
	 * ...
	 * @author parasitic
	 */
	public class ConstructPoint extends FilterPoint 
	{
		protected var valid:Boolean = true;
		
		public var building:Boolean;
		
		public var complete:Boolean;
		
		public function isComplete():Boolean
		{
			return complete;
		}
		
		public function setComplete(b:Boolean):void
		{
			complete = b;
		}
		
		public function setBuilding(b:Boolean):void
		{
			building = b;
		}
		
		public function isBuilding():Boolean
		{
			return building;
		}
		
		public function updateValid(nowValid:Boolean):void
		{
			if (!isValid() && nowValid)
			{
				setStatus(true);
				return;
			}
			else if (isValid() && !nowValid)
			{
				setStatus(false);
				return;
			}
		}
		
		public function setStatus(valid:Boolean):void
		{
			switch(valid)
			{
				case true:
					drawHighlightValid();
					setValid(true);
					break;
				
				case false:
					//highlight invalid
					drawHighlightInvalid();
					setValid(false);
					break;
			}
		}
		
		public function drawHighlightValid():void
		{
			clear();
			addFilter(Colors.Green, .8, 20, false, false);
			refresh();
		}
		
		public function drawHighlightInvalid():void
		{
			clear();
			addFilter(Colors.Red, .8, 20, false, false);
			refresh();
		}
		
		public function setValid(b:Boolean):void
		{
			valid = b;
		}
		
		public function isValid():Boolean
		{
			return valid;
		}
		
		public function startBuild():void
		{
			startDrag(true, utils.Rect);
			setBuilding(true);
			setComplete(false);
			drawHighlightValid();
			setValid(true);
		}
		
		public function stopBuild():void
		{
			stopDrag();
			/*
			set_x(utils.round( get_x()) );
			set_y(utils.round( get_y()) );
			*/
			setBuilding(false);
			setComplete(true);
			clear();
			refresh();
		}
	}

}